﻿#pragma once


#ifndef CCTPPROVIDER_H
#define CCTPPROVIDER_H

#include "CTP\ThostFtdcMdApi.h"
#include "CTP\ThostFtdcTraderApi.h"
#include "SmartTrade\SmartTradecUserApiStruct.h"
#include "MarketDataApiType.h"
#include "BaseProvider.h"

#include <string>
#include <vector>
#include <set>

using namespace std;

//#define _CTPPROVIDER_SEPS_ ",;"

#ifdef __cplusplus
extern "C" {
#endif

namespace SmartTrade{

	////////////////////////////////////////////////////////////////////////
	/// @file: CCTPProvider.h
	///	@copyright:  SmartTrade Company.
	/// @author： 王宇
	/// @create： 2013/07/05
	/// @brief：
	///			1、ctp的provier接口，继承自base provider和CThostFtdcMdSpi
	///			2、对接ctp传入订阅标的的信息
	///			3、接收ctp返回的数据，并传递自相应的数据处理模块
	/// @history
	////////////////////////////////////////////////////////////////////////
	class CCTPProvider : public CThostFtdcMdSpi,public BaseProvider
	{
	public:
		CCTPProvider(void);
		~CCTPProvider(void);

	public://公开方法
		virtual void Connect(const string& strAddresses,const string& strBrokerId,
						const string& strLoginId,const string& strPassword);
		virtual void Disconnect();
		virtual void Subscribe(const string& strInstrumentIds);
		virtual void Subscribe(const set<string>& setInstId);
		virtual void UnSubscribe(const string& strInstrumentIds);
		virtual void UnSubscribe(const set<string>& setInstId);
	private:
		virtual void OnFrontConnected();
		virtual void OnFrontDisconnected(int iReason);
		virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin,
										CThostFtdcRspInfoField *pRspInfo, int iRequestId, bool bIsLast);
		virtual void OnRspSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument,
										CThostFtdcRspInfoField *pRspInfo, int iRequestId, bool bIsLast);
		virtual void OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, 
											CThostFtdcRspInfoField *pRspInfo, int iRequestID, bool bIsLast);
		virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *depthMarketData);
		bool IsErrorRspInfo(CThostFtdcRspInfoField *rspInfo);//不送出错消息

	private:
		CThostFtdcMdApi*			pMdApi_;			//行情API
		int							iRequestId_;		//请求ID，每次请求前自增
	public:
		static const string STR_PROVIDER_NAME;		//提供程序名称
		static const bool B_IS_REGISTED;				//提供程序注册
	};
}//namespace SmartTrade

#ifdef __cplusplus
}
#endif

#endif // CCTPPROVIDER_H
